<?php

namespace App\Library\Requests\Product;

use App\Library\Requests\Base\BaseDTORequest;
use App\Library\Rules\MediasImgRule;
use App\Library\Rules\MediaVideoRule;
use App\Library\Rules\ShopProductSpecNumbersRule;

class ProductAddRequest extends BaseDTORequest
{
    public function rules(): array
    {
        $array = [
            'categoryId_1' => 'required|integer',
            'categoryId_2' => 'required|integer',
            'categoryId_3' => 'required|integer',
            'status' => 'required|integer|in:1,2',
            'name' => 'required|string|max:255',
            'label' => 'nullable|string|max:255',
            'note' => 'nullable|string|max:255',
            'content' => 'nullable|string|max:255',
            'brand' => 'nullable|string|max:255',
            'activity' => 'nullable|integer|between:0,3',
            'activityType' => 'nullable|integer',
            'specialStartTime' => 'nullable|integer|min:0',
            'specialEndTime' => 'nullable|integer|min:0|after_or_equal:specialStartTime',
            'subPrice' => 'nullable|decimal:2',
            'specJson' => ['required', 'array', new ShopProductSpecNumbersRule],
            'mainImgIds' => ['required', 'array', new MediasImgRule],
            'descImgIds' => ['nullable', 'array', new MediasImgRule],
            'videoId' => ['nullable', 'string', new MediaVideoRule],
            //'psIdJson' => 'nullable|string',
            //'avatarImgIdJson' => 'nullable|string',
            //'contentImgIdJson' => 'nullable|string',
        ];
        if ($this->categoryId_1 === 1) {
            return array_merge($array, [
                'protect' => 'nullable|string|max:255',
                'wildCare' => 'nullable|integer|in:1,2',
                'stage' => 'nullable|integer|between:0,3',
                'gene' => 'nullable|string|max:255',
                'feedHdId' => 'nullable|integer|min:0',
                'guideHdId' => 'nullable|integer|min:0',
                'petCode' => 'nullable|string|max:50',
            ]);
        } else {
            return array_merge($array, [
                'toolSpecies' => 'nullable|string|max:255',
                'toolStage' => 'nullable|string|max:255',
            ]);
        }
    }
}
